package com.yunxin.admin.system.application.assembler;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunxin.admin.system.application.command.*;
import com.yunxin.admin.system.application.dto.*;
import com.yunxin.admin.system.domain.model.user.*;
import com.yunxin.admin.system.infra.persistence.entity.query.condition.UserPageCondition;
import com.yunxin.admin.system.infra.persistence.entity.query.result.UserExportResult;
import com.yunxin.admin.system.infra.persistence.entity.query.result.UserInfoResult;
import com.yunxin.admin.system.infra.persistence.entity.query.result.UserMerchantInfoResult;
import com.yunxin.admin.system.infra.persistence.entity.query.result.UserPageResult;
import com.yunxin.admin.system.domain.model.user.UserSimple;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

/**
 * 用户对象转换器
 *
 * @author zero°
 * @since 2023-05-22
 */
@Mapper(componentModel = "spring")
public interface UserAssembler {

    /**
     * result 转 dto
     * @param result result
     * @return UserDetailDTO
     */
    UserDetailDTO toUserDetailDTO(UserInfoResult result);
    /**
     * result 转 dto
     * @param result result
     * @return UserPageDTO
     */
    @Mapping(target = "genderLabel", expression = "java(com.yunxin.common.base.IBaseEnum.getLabelByValue(result.getGender(), com.yunxin.admin.system.infra.common.enums.GenderEnum.class))")
    UserPageDTO toUserPageDTO(UserPageResult result);

    /**
     * result 转 dto
     * @param result result
     * @return Page<UserPageDTO>
     */
    UserExportDTO toUserExportDTO(UserExportResult result);
    /**
     * result 转 dto
     * @param resultPage resultPage
     * @return Page<UserPageDTO>
     */
    Page<UserPageDTO> toUserPageDTO(Page<UserPageResult> resultPage);

    /**
     * result 转 dto
     * @param result result
     * @return UserPageDTO
     */
    @Mapping(target = "genderLabel", expression = "java(com.yunxin.common.base.IBaseEnum.getLabelByValue(result.getGender(), com.yunxin.admin.system.infra.common.enums.GenderEnum.class))")
    UserMerchantPageDTO toUserMerchantPageDTO(UserMerchantInfoResult result);

    /**
     * result 转 dto
     * @param resultPage resultPage
     * @return Page<UserMerchantPageDTO>
     */
    Page<UserMerchantPageDTO> toUserMerchantPageDTO(Page<UserMerchantInfoResult> resultPage);

    /**
     * entity 转 dto
     * @param entity entity
     * @return UserInfoDTO
     */
    @Mapping(target = "userId", source = "id")
    UserInfoDTO toUserInfoDTO(User entity);


    /**
     * entity 转 dto
     * @param entity entity
     * @return UserInfoDTO
     */
    @Mapping(target = "userId", source = "id")
    UserInfoDTO toUserInfoDTO(UserSimple entity);


    /**
     * request 转 condition
     * @param request request
     * @return UserPageCondition
     */
    UserPageCondition formUserPageCondition(UserPageCommand request);
    /**
     * command 转 entity
     * @param command command
     * @return User
     */
    User formAddUserCommand(AddUserCommand command);

    /**
     * Command 转 entity
     * @param request request
     * @return User
     */
    User formAddUserMerchantCommand(AddUserMerchantCommand request);
    /**
     * command 转 entity
     * @param command command
     * @return User
     */
    User formUpdateUserCommand(UpdateUserCommand command);
    /**
     * command 转 command
     * @param command command
     * @return User
     */
    User formUpdateUserMerchantCommand(UpdateUserMerchantCommand command);
    /**
     * dto 转 entity
     * @param dto dto
     * @return SysCoreUser
     */
    User formUserImportDTO(UserImportDTO dto);

}
